package com.shell.governor.user.rx;

import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.framework.utils.MessageSender;
import com.shell.governor.modules.message.keyword.UserRejectKeyword;
import com.shell.governor.user.UserEvent;
import com.shell.governor.user.dao.PubUserOptDao;
import com.shell.governor.user.po.PubUser;
import com.shell.governor.user.po.PubUserOpt;
import com.shell.properties.GovernorProperties;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SendUserRejectMsgSubscriber extends OnErrorNotImplementedSubscriber<UserEvent> {
	@Autowired
	PubUserOptDao userOptDao;
	@Autowired
	GovernorProperties governorProperties;

	public void onApplicationEvent(UserEvent event) {
		PubUser user = event.getUser();
		PubUserOpt opt = event.getUserOpt();

		List<PubUserOpt> opts = this.userOptDao.getLastOpt(opt.getUserId(), opt.getEntId());

		PubUserOpt firstOpt = (PubUserOpt) opts.get(opts.size() - 1);

		UserRejectKeyword keyword = new UserRejectKeyword();
		keyword.setUserName(user.getUserName());
		keyword.setApplyDate(firstOpt.getOprTime().substring(0, 10));
		keyword.setUrl(this.governorProperties.getUrl());

		MessageSender.sendMessageByTmpl(CommonDataUtil.getCurEntId(), "MT06010", keyword, opt.getEntId());

		MessageSender.sendMessageByTmpl(CommonDataUtil.getCurEntId(), "MT06011", keyword, opt.getEntId());
	}
}
